package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.OrderMapper;
import com.qf.entitys.Order;
import com.qf.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper mapper;

    @Override
    public int deleteByPrimaryKey(String outTradeNo) {
        return mapper.deleteByPrimaryKey(outTradeNo);
    }

    @Override
    public int insert(Order record) {
        return 0;
    }

    @Override
    public int insertSelective(Order record) {
        return 0;
    }

    @Override
    public Order selectByPrimaryKey(String outTradeNo) {
        return mapper.selectByPrimaryKey(outTradeNo);
    }

    @Override
    public PageInfo<Order> selectPayBusiness(Integer id, Integer pageindex) {
        PageHelper.startPage(pageindex,10);
        List<Order> orders = mapper.selectPayBusiness(id);
        PageInfo<Order> pageInfo=new PageInfo<>(orders);
        return pageInfo;
    }

    @Override
    public PageInfo<Order> queryPayBusiness(Integer id, Integer pageindex, Integer type) {
        PageHelper.startPage(pageindex,10);
        List<Order> orders = mapper.queryPayBusiness(id,type);
        PageInfo<Order> pageInfo=new PageInfo<>(orders);
        return pageInfo;
    }

    @Override
    public Order selectByPrimaryKeyAndShipaddress(String outTradeNo) {
        return mapper.selectByPrimaryKeyAndShipaddress(outTradeNo);
    }

    @Override
    public int updateByPrimaryKeySelective(Order record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Order record) {
        return 0;
    }

    @Override
    public List<Order> selectUserid(Integer id) {
        return mapper.selectUserid(id);
    }

    @Override
    public PageInfo<Order> selectPayBusiness(Order order,Integer pageindex) {
        PageHelper.startPage(pageindex,10);
        List<Order> orders = mapper.selectPayBusiness(order);
        List<Order> orders1=new ArrayList<>();

        for (int i=0;i<orders.size();i++){
            if (orders.get(i).getOrderType()!=7){
                orders1.add(orders.get(i));
            }

        }
        PageInfo<Order> pageInfo=new PageInfo<>(orders1);
        return pageInfo;
    }


    @Override
    public List<Order> queryByPrimaryKey(Integer id,String outTradeNo) {
        String no="%"+outTradeNo+"%";
        return mapper.queryByPrimaryKey(id, no);
    }

    @Override
    public List<Order> queryByPrimaryKeyAndType(Integer id, String outTradeNo, Integer type) {
        return mapper.queryByPrimaryKeyAndType(id,outTradeNo,type);
    }
}
